//
//  AdviceVC.m
//  一键联IOS
//
//  Created by 徐绍明 on 15/12/28.
//  Copyright © 2015年 xufei. All rights reserved.
//

#import "AdviceVC.h"
#import "PlaceholderTextView.h"
@interface AdviceVC ()

@end

@implementation AdviceVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBarHidden = YES;
    self.view.backgroundColor = [UIColor whiteColor];
    [self creatNav];
    
   view = [[PlaceholderTextView alloc] initWithFrame:CGRectMake(0, 70, WIDE, 200)];
    
    view.delegate =self;
    
    
    view.placeholder = @"这一刻，你想说些什么？";
    view.font =[UIFont boldSystemFontOfSize:14];
    view.placeholderFont=[UIFont boldSystemFontOfSize:13];
   // view.placeholderColor =
    view.layer.borderWidth=0.5;
    view.layer.borderColor=[UIColor lightGrayColor].CGColor;
    
    
    view.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    view.scrollEnabled = YES;
    
    
    [self.view addSubview:view];


   
    view.layer.borderColor = RGB_COLOR(0x00c49f).CGColor;
    view.layer.borderWidth = 2.0f;
    view.layer.cornerRadius = 6.0f;
//   
//     _textview.keyboardType = UIKeyboardAppearanceDefault;
//    [self.view addSubview:_textview];
    
    
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(10, 280, WIDE-20, 30);
    btn.backgroundColor = RGB_COLOR(0x00c49f);
    [btn setTitle:@"提交" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(btnclick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    
    
    
    
}
-(void)btnclick{
    [view resignFirstResponder];
    NSLog(@"_str %@",_str);
    
}

-(BOOL)textViewShouldBeginEditing:(UITextView *)textView{
    return YES;
}
//-(void)textViewDidChange:(UITextView *)textView{
//    //计算文本的高度
//    CGSize constraintSize;
//    constraintSize.width = textView.frame.size.width-16;
//    constraintSize.height = MAXFLOAT;
//    CGSize sizeFrame =[textView.text sizeWithFont:textView.font
//                                constrainedToSize:constraintSize
//                                    lineBreakMode:UILineBreakModeWordWrap];
//    
//    //重新调整textView的高度
//    textView.frame = CGRectMake(textView.frame.origin.x,textView.frame.origin.y,textView.frame.size.width,sizeFrame.height+10);
//}
-(void)textViewDidChange:(UITextView *)textView{
    if (textView.text.length>=2000) {
         SHOW_ALERT(@"请输入2000字符以内的文字或数字！");
    }
    textView.text =[textView.text substringToIndex:20];
    _str = textView.text;

}
//-(void)textViewDidEndEditing:(UITextView *)textView{
//    NSLog(@"%@",textView.text);
//    if (textView.text.length ==0) {
//        _str =@"";
//    }
//     _str = textView.text;
//}
//-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
//    if (range.location>=200) {
//        SHOW_ALERT(@"请输入100字符以内的文字或数字！");
//        return NO;
//    }
//    if ([text isEqualToString:@"\n"]) {
//        return NO;
//    }
//   return YES;
//   
//}


-(void)creatNav{
    UIView *navView = [[UIView alloc] initWithFrame:CGRectMake(0, 20, WIDE, 44)];
    navView.backgroundColor = RGB_COLOR(0x00c49f);
    [self.view addSubview:navView];
    
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(10, 7, 30, 30);
    leftBtn.layer.cornerRadius = 20;
    [leftBtn setImage:[UIImage imageNamed:@"返回箭头"] forState:UIControlStateNormal] ;
    [leftBtn addTarget:self action:@selector(backBtn) forControlEvents:UIControlEventTouchUpInside];
    [navView addSubview:leftBtn];
    
    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(WIDE/2-60, 7, 120, 30  )];
    title.text = @"意见反馈";
    title.textAlignment = NSTextAlignmentCenter;
    title.textColor = [UIColor whiteColor];
    [navView addSubview:title];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
